using logging;
using System.Collections;

interface Component{
    void info();
}

class Person: Component{
    public string name{get;set;}
    public string title{get;set;}
    public Person(string name){ this.name = name; title = "小兵"; }
    public virtual void info(){
        Log.print(title + ": " + name);
    }
}

class Manager: Person{
    public ArrayList _group = new ArrayList();
    public Manager(Person man, string title): base(man.name){
        this.title = title;
    }

    public void add_manager(Manager manager){
        _group.Add(manager);
    }
    public void add_person(Person man){
        _group.Add(man);
    }
    public override void info(){  // 重写：递归查询
        base.info();
        foreach(Person item in _group){
            // if(item.GetType() == typeof(Manager))  // u don't need to judge the type
                item.info();
        }
    }
}

class Demo{
    static void Main(){
        var chairman = new Manager(new Person("Hello"), "董事长");  // the top.
        var Tesla = new Manager(new Person("Tesla"), "美国分公司经理");
        var WangPeng = new Manager(new Person("WangPeng"), "中国分公司经理");
        chairman.add_manager(Tesla);
        chairman.add_manager(WangPeng);
        chairman.add_person(new Person("最美小蜜"));

        var aa = new Manager(new Person("aa.zhao"), "财务部经理");  Tesla.add_manager(aa);
        var bb = new Manager(new Person("bb.qian"), "人事部经理");  Tesla.add_manager(bb);
        var cc = new Manager(new Person("cc.sun"), "技术部经理");  Tesla.add_manager(cc);
        var dd = new Person("孤单的小蜜");  Tesla.add_person(dd);

        var ee = new Person("ee");  cc.add_person(ee);
        var ff = new Person("ff");  cc.add_person(ff);
        var gg = new Person("gg");  cc.add_person(gg);
        var mm = new Person("打不死的小蜜");  cc.add_person(mm);

        chairman.info();
        mm.info();  // 无论是谁，我们的接口相同
    }
}
